Avoid using $_ when loading the commands from namespaces#2181
Open
bbrtj wants to merge 1 commit intomojolicious:mainfrom
Open
Avoid using $_ when loading the commands from namespaces#2181bbrtj wants to merge 1 commit intomojolicious:mainfrom
bbrtj wants to merge 1 commit intomojolicious:mainfrom
Conversation
f6c8a1f to
91c03a9
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the command-loading loop to avoid using the implicit $_, preventing unintended global variable pollution.
- Replaced a chained
grep/forusing$_with an explicitfor my $pkgloop. - Added an early
next unless _command($pkg)guard. - Updated the hash assignment to use the named
$pkgvariable.
Comments suppressed due to low confidence (3)
lib/Mojolicious/Commands.pm:68
- [nitpick] Consider renaming
$pkgto a more descriptive name like$moduleor$command_classto clarify that it represents a command class.
for my $pkg (find_modules($ns), find_packages($ns)) {
lib/Mojolicious/Commands.pm:67
- [nitpick] Add a comment explaining that this loop avoids using
$_to prevent pollution from upstream code, clarifying the purpose of the refactoring.
for my $ns (@{$self->namespaces}) {
lib/Mojolicious/Commands.pm:71
- Consider adding a test case to verify that command loading no longer pollutes
$_, ensuring this transformation addresses the original issue (#2175).
}
Author
|
Bump, why isn't this merged? Seems like a low-hanging fruit. |
Member
|
Nobody will even look at it before tests passed, |
Author
|
I'm confused. Am I required to take any action here? Did the tests fail? They look like they never ran at all. |
Member
|
No idea what went wrong i'm afraid, and nothing we can do about it. |
Author
|
I rebased to latest main. Seems like workflows await approval now. Maybe that'll fix them. |
Author
|
Most tests passed now. Windows test seems to be failing in other PRs too, regardless of their content. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Solution proposed in #2175
Motivation
Polluting
$_can happen deep down in dependencies tree of the loaded command.References
resolves #2175